package com.temc.kafka.producer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 *
 * @author 辛凤文
 * @since 1.0
 **/
@Slf4j
@Component
public class KafkaNormalProducer {

    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;

    private long msgId = 1;

    public void sendKafkaMsg() {
        //topic：主题 key：分区  data：数据
        //kafkaTemplate.send("test-topic", "key1", "kafkaTest" + msgId);
        kafkaTemplate.send("test-topic", "kafkaTest" + msgId);
        log.info("已发送消息{}", msgId++);
    }
}
